// created on 25/04/2006 at 21:34
using System;
using Gtk;
using System.Collections;
using System.IO;

public class ComputerGamersPerfect : ComputerGamersInterface
{
	public string getComputerGamerDescription() {
		return "Perfect Player. Impossible To Win?";
	}

	public string getComputerGamerDefaultNamePlayer() {
		return "ComputerPerfectPlayer";
	}

	public void computeNewMovement(int sizeOfBoard,ButtonInterface[] buttons, out ButtonInterface button1, out ButtonInterface button2) {
		Hashtable buttonToShow=new Hashtable();
		ArrayList bi=new ArrayList();
		Random rnd=new Random();
		String key="";
		button1=button2=null;

		// Build the arraylist with the list of buttons to show.
		for (int i=0; i<sizeOfBoard; i++) {
			if (!buttons[i].isImgVisible()) {
				key=buttons[i].getNameButton();
				if (key!="") {
					object obj=buttonToShow[key];
					if (obj!=null) {
						button1=(ButtonInterface)obj;
						button2=buttons[i];
						break;
					} else {
						buttonToShow.Add(key,(object)buttons[i]);
						bi.Add(buttons[i]);
					}
				} else {
					bi.Add(buttons[i]);
				}
			}
		}

		// Choose two button random.if not found any coupple
		if (button1==null) {
			button1=(ButtonInterface)bi[rnd.Next(bi.Count)];
			bi.Remove(button1);
			button2=(ButtonInterface)bi[rnd.Next(bi.Count)];
		}
	}
}
